
import React, { useState } from 'react'
import { Button, Input, message } from 'antd';
import './index.scss'
import useStores from 'Stores';
const { TextArea } = Input;
interface Props {
  zcomid: number|undefined
  momentId : number| undefined
  onChangeModel:(value: boolean) => void
  onFetch:()=>void
}



const CommentDeatil = ({zcomid,momentId,
 onChangeModel,
 onFetch
}: Props) => {
  const {root} = useStores()
  const [content,setContent] = useState<string>('')
  

  const onChange = (e:any) => {
    console.log('Change:', e.target.value);
    setContent(e.target.value)
  };

  const onCommenOther=async()=>{
    if(!content.length){
      message.error(`评论不能为空`)
      return
    }
    console.log('pinglun');
    console.log(zcomid);
   
    const res = await root.onCommentOther(
      zcomid,
      momentId,
      content
    )
    if (res.affectedRows === 1) {
      message.success('评论成功')
      onChangeModel(false)
      onFetch()
      return
    }
    message.error(`评论失败！${res}`)
  }


  return (<>
       <TextArea placeholder="请输入你的评论" allowClear onChange={onChange}></TextArea>
       <div className='btn'>
       <Button type="primary" style={{marginTop:'5px'}} onClick={()=>{onCommenOther()}}>发表评论</Button>
       </div>
  </>)
}

export default CommentDeatil
